const express = require('express')
const path = require('path')
function simpleServer(port, dist, distPre) {
  const app = express()
  // app.use((req, res, next) => {
  //   console.log(req.url)
  //   next()
  // })
  if (dist) {
    dist = path.isAbsolute(dist) ? path.resolve(dist) : path.join(process.cwd(), dist)
    if (distPre) {
      app.use(distPre, express.static(dist))
    } else {
      app.use(express.static(dist))
    }
  }
  let server = app.listen(port)
  console.info(`now server is on port ${port}`)
  app.server = server
  return app
}
module.exports = simpleServer
